package tpdisenio2009.mvp.display;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import tpdisenio2009.model.beans.User;
import tpdisenio2009.mvp.presenter.GlobalTournamentTablePresenter;
import tpdisenio2009.mvp.presenter.QueryFantasyTeamPresenter;
import tpdisenio2009.mvp.presenter.TournamentDateWinnersPresenter;

/**
 *
 * @author Nicolás Kreiff
 */
public class MainUserScreenViewImpl extends javax.swing.JFrame implements MainUserScreenView {

    /** Creates new form MainUserScreenViewImpl */
    public MainUserScreenViewImpl() {
        initComponents();

        QueryFantasyTeamViewImpl queryTeamView = new QueryFantasyTeamViewImpl();
        QueryFantasyTeamPresenter queryTeamPresenter = new QueryFantasyTeamPresenter( queryTeamView );
        jTabbedPane.add( "Consultar Equipo", queryTeamPresenter.getView().asWidget() );

        TournamentDateWinnersViewImpl dateWinnersView = new TournamentDateWinnersViewImpl();
        TournamentDateWinnersPresenter dateWinnersPresenter = new TournamentDateWinnersPresenter( dateWinnersView );
        jTabbedPane.add("Ganadores por fecha", dateWinnersPresenter.getView().asWidget() );
        if (!dateWinnersPresenter.hasDates())
            jTabbedPane.setEnabledAt( 1, false );

        GlobalTournamentTableViewImpl globalTableView = new GlobalTournamentTableViewImpl();
        GlobalTournamentTablePresenter globalTablePresenter = new GlobalTournamentTablePresenter( globalTableView );
        jTabbedPane.add( "Tabla General", globalTablePresenter.getView().asWidget() );
        if (!globalTablePresenter.hasDates())
            jTabbedPane.setEnabledAt( 2, false );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        Dimension dim = this.getToolkit().getScreenSize();
        this.setLocation((dim.width - this.getWidth()) / 2,(dim.height - this.getHeight()) / 2);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane = new javax.swing.JTabbedPane();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabelUserLogged = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(tpdisenio2009.Tpdisenio2009App.class).getContext().getResourceMap(MainUserScreenViewImpl.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setLocationByPlatform(true);
        setName("Form"); // NOI18N

        jTabbedPane.setName("jTabbedPane"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabelUserLogged.setFont(resourceMap.getFont("jLabelUserLogged.font")); // NOI18N
        jLabelUserLogged.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelUserLogged.setText(resourceMap.getString("jLabelUserLogged.text")); // NOI18N
        jLabelUserLogged.setName("jLabelUserLogged"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 882, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 650, Short.MAX_VALUE)
                        .addComponent(jLabelUserLogged)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jLabel1)
                    .addComponent(jLabelUserLogged))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 449, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelUserLogged;
    private javax.swing.JTabbedPane jTabbedPane;
    // End of variables declaration//GEN-END:variables

    public void setUserLogged(User user) {
        jLabelUserLogged.setText( user.getLastName() + ", " + user.getFirstName() );
    }

    public void addCloseListener(ActionListener listener) {
        jButton1.addActionListener(listener);
    }

    public void removeCloseListener(ActionListener listener) {
        jButton1.removeActionListener(listener);
    }

    public boolean showConfirmation( String notifiactionMessage ) {
        int confirm = JOptionPane.showConfirmDialog( this, notifiactionMessage, "Confirmación", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE );

        if (JOptionPane.YES_OPTION == confirm)
            return true;
        else
            return false;
    }   
    
    public Component asWidget() {
        return this;
    }
}
